import * as user from '../services/user'

export default {
    namespace: 'user',
    state: {
        account: null,
        token: null,
        name: null,
    },
    reducers: {
        login(state, action) {
            return {
                ...state,
                ...action.data,
            }
        },
        logout(state) {
            return {
                ...state,
                account: null,
                token: null,
                name: null,
            }
        },
    },
    effects: {
        * POST_login(action, { call, put }) {
            const { data } = yield call(user.searchRepositories)
            yield put({ type: 'login', data })
        },
        * POST_logout(action, { call, put }) {
            // const { data } = yield call(user.postLogin)
            yield put({ type: 'logout' })
        },
    },
}
